package com.atguigu.aiproject.entity;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@TableName("users") //指定哪张表
@Data
@NoArgsConstructor
@AllArgsConstructor
public class User {
    @TableId(value = "u_id")//指定主键
    private Integer id;
    @TableField(value = "u_nickname")//昵称
    private String nickName;//昵称
    @TableField(value = "u_loginname")
    private String loginName;
    @TableField(value = "u_loginpwd")//登录密码
    private String loginPwd;
    @TableField(value = "u_score")//积分
    private int score;
    @TableField(value = "u_email")//邮箱
    private String email;
    @TableField(value = "u_role")//角色，0-管理员，1-员工
    private int role;
    @TableField(value = "u_avatar")
    private String avatar;
    @TableField(value = "online_status")
    private Boolean onlineStatus;
    @TableField(value = "last_online_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime lastOnlineTime;
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;
    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updateTime;

    public enum Role {
        USER, ADMIN
    }
    @JsonIgnore
    public boolean isAdmin() {
        return role == Role.ADMIN.ordinal();
    }
    //辅助方法，用于聊天背景使用
    @JsonIgnore
    public String getUserId() {
        return String.valueOf(this.id);
    }
}